// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Aggregations;

public sealed partial class GeohashGridAggregation
{
	/// <summary>
	/// <para>
	/// The bounding box to filter the points in each bucket.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("bounds")]
	public Elastic.Clients.Elasticsearch.Serverless.GeoBounds? Bounds { get; set; }

	/// <summary>
	/// <para>
	/// Field containing indexed <c>geo_point</c> or <c>geo_shape</c> values.
	/// If the field contains an array, <c>geohash_grid</c> aggregates all array values.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("field")]
	public Elastic.Clients.Elasticsearch.Serverless.Field? Field { get; set; }

	/// <summary>
	/// <para>
	/// The string length of the geohashes used to define cells/buckets in the results.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("precision")]
	public Elastic.Clients.Elasticsearch.Serverless.GeohashPrecision? Precision { get; set; }

	/// <summary>
	/// <para>
	/// Allows for more accurate counting of the top cells returned in the final result the aggregation.
	/// Defaults to returning <c>max(10,(size x number-of-shards))</c> buckets from each shard.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("shard_size")]
	public int? ShardSize { get; set; }

	/// <summary>
	/// <para>
	/// The maximum number of geohash buckets to return.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("size")]
	public int? Size { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.Serverless.Aggregations.Aggregation(GeohashGridAggregation geohashGridAggregation) => Elastic.Clients.Elasticsearch.Serverless.Aggregations.Aggregation.GeohashGrid(geohashGridAggregation);
}

public sealed partial class GeohashGridAggregationDescriptor<TDocument> : SerializableDescriptor<GeohashGridAggregationDescriptor<TDocument>>
{
	internal GeohashGridAggregationDescriptor(Action<GeohashGridAggregationDescriptor<TDocument>> configure) => configure.Invoke(this);

	public GeohashGridAggregationDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.GeoBounds? BoundsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Field? FieldValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.GeohashPrecision? PrecisionValue { get; set; }
	private int? ShardSizeValue { get; set; }
	private int? SizeValue { get; set; }

	/// <summary>
	/// <para>
	/// The bounding box to filter the points in each bucket.
	/// </para>
	/// </summary>
	public GeohashGridAggregationDescriptor<TDocument> Bounds(Elastic.Clients.Elasticsearch.Serverless.GeoBounds? bounds)
	{
		BoundsValue = bounds;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Field containing indexed <c>geo_point</c> or <c>geo_shape</c> values.
	/// If the field contains an array, <c>geohash_grid</c> aggregates all array values.
	/// </para>
	/// </summary>
	public GeohashGridAggregationDescriptor<TDocument> Field(Elastic.Clients.Elasticsearch.Serverless.Field? field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Field containing indexed <c>geo_point</c> or <c>geo_shape</c> values.
	/// If the field contains an array, <c>geohash_grid</c> aggregates all array values.
	/// </para>
	/// </summary>
	public GeohashGridAggregationDescriptor<TDocument> Field<TValue>(Expression<Func<TDocument, TValue>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Field containing indexed <c>geo_point</c> or <c>geo_shape</c> values.
	/// If the field contains an array, <c>geohash_grid</c> aggregates all array values.
	/// </para>
	/// </summary>
	public GeohashGridAggregationDescriptor<TDocument> Field(Expression<Func<TDocument, object>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The string length of the geohashes used to define cells/buckets in the results.
	/// </para>
	/// </summary>
	public GeohashGridAggregationDescriptor<TDocument> Precision(Elastic.Clients.Elasticsearch.Serverless.GeohashPrecision? precision)
	{
		PrecisionValue = precision;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Allows for more accurate counting of the top cells returned in the final result the aggregation.
	/// Defaults to returning <c>max(10,(size x number-of-shards))</c> buckets from each shard.
	/// </para>
	/// </summary>
	public GeohashGridAggregationDescriptor<TDocument> ShardSize(int? shardSize)
	{
		ShardSizeValue = shardSize;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The maximum number of geohash buckets to return.
	/// </para>
	/// </summary>
	public GeohashGridAggregationDescriptor<TDocument> Size(int? size)
	{
		SizeValue = size;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (BoundsValue is not null)
		{
			writer.WritePropertyName("bounds");
			JsonSerializer.Serialize(writer, BoundsValue, options);
		}

		if (FieldValue is not null)
		{
			writer.WritePropertyName("field");
			JsonSerializer.Serialize(writer, FieldValue, options);
		}

		if (PrecisionValue is not null)
		{
			writer.WritePropertyName("precision");
			JsonSerializer.Serialize(writer, PrecisionValue, options);
		}

		if (ShardSizeValue.HasValue)
		{
			writer.WritePropertyName("shard_size");
			writer.WriteNumberValue(ShardSizeValue.Value);
		}

		if (SizeValue.HasValue)
		{
			writer.WritePropertyName("size");
			writer.WriteNumberValue(SizeValue.Value);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class GeohashGridAggregationDescriptor : SerializableDescriptor<GeohashGridAggregationDescriptor>
{
	internal GeohashGridAggregationDescriptor(Action<GeohashGridAggregationDescriptor> configure) => configure.Invoke(this);

	public GeohashGridAggregationDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.GeoBounds? BoundsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Field? FieldValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.GeohashPrecision? PrecisionValue { get; set; }
	private int? ShardSizeValue { get; set; }
	private int? SizeValue { get; set; }

	/// <summary>
	/// <para>
	/// The bounding box to filter the points in each bucket.
	/// </para>
	/// </summary>
	public GeohashGridAggregationDescriptor Bounds(Elastic.Clients.Elasticsearch.Serverless.GeoBounds? bounds)
	{
		BoundsValue = bounds;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Field containing indexed <c>geo_point</c> or <c>geo_shape</c> values.
	/// If the field contains an array, <c>geohash_grid</c> aggregates all array values.
	/// </para>
	/// </summary>
	public GeohashGridAggregationDescriptor Field(Elastic.Clients.Elasticsearch.Serverless.Field? field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Field containing indexed <c>geo_point</c> or <c>geo_shape</c> values.
	/// If the field contains an array, <c>geohash_grid</c> aggregates all array values.
	/// </para>
	/// </summary>
	public GeohashGridAggregationDescriptor Field<TDocument, TValue>(Expression<Func<TDocument, TValue>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Field containing indexed <c>geo_point</c> or <c>geo_shape</c> values.
	/// If the field contains an array, <c>geohash_grid</c> aggregates all array values.
	/// </para>
	/// </summary>
	public GeohashGridAggregationDescriptor Field<TDocument>(Expression<Func<TDocument, object>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The string length of the geohashes used to define cells/buckets in the results.
	/// </para>
	/// </summary>
	public GeohashGridAggregationDescriptor Precision(Elastic.Clients.Elasticsearch.Serverless.GeohashPrecision? precision)
	{
		PrecisionValue = precision;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Allows for more accurate counting of the top cells returned in the final result the aggregation.
	/// Defaults to returning <c>max(10,(size x number-of-shards))</c> buckets from each shard.
	/// </para>
	/// </summary>
	public GeohashGridAggregationDescriptor ShardSize(int? shardSize)
	{
		ShardSizeValue = shardSize;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The maximum number of geohash buckets to return.
	/// </para>
	/// </summary>
	public GeohashGridAggregationDescriptor Size(int? size)
	{
		SizeValue = size;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (BoundsValue is not null)
		{
			writer.WritePropertyName("bounds");
			JsonSerializer.Serialize(writer, BoundsValue, options);
		}

		if (FieldValue is not null)
		{
			writer.WritePropertyName("field");
			JsonSerializer.Serialize(writer, FieldValue, options);
		}

		if (PrecisionValue is not null)
		{
			writer.WritePropertyName("precision");
			JsonSerializer.Serialize(writer, PrecisionValue, options);
		}

		if (ShardSizeValue.HasValue)
		{
			writer.WritePropertyName("shard_size");
			writer.WriteNumberValue(ShardSizeValue.Value);
		}

		if (SizeValue.HasValue)
		{
			writer.WritePropertyName("size");
			writer.WriteNumberValue(SizeValue.Value);
		}

		writer.WriteEndObject();
	}
}